package br.com.fabrica.aid.aid_fabrica.view;

import java.util.Iterator;
import java.util.List;
import javax.inject.Inject;
import br.com.fabrica.aid.aid_fabrica.business.UsuarioBC;
import br.com.fabrica.aid.aid_fabrica.domain.Usuario;
import br.gov.frameworkdemoiselle.annotation.NextView;
import br.gov.frameworkdemoiselle.annotation.PreviousView;
import br.gov.frameworkdemoiselle.stereotype.ViewController;
import br.gov.frameworkdemoiselle.template.AbstractListPageBean;
import br.gov.frameworkdemoiselle.transaction.Transactional;


@ViewController
@NextView("./usuario_edit.xhtml")
@PreviousView("./usuario_list.xhtml")
public class UsuarioListMB extends AbstractListPageBean<Usuario, Long>{
	
	private static final long serialVersionUID = 1L;

	@Inject
	private UsuarioBC us;

	@Override
	protected List<Usuario> handleResultList() {
		return this.us.findAll();
	}

	@Transactional
	public String deleteSelection() {
		boolean delete;
		for (Iterator<Long> iter = getSelection().keySet().iterator(); iter.hasNext();) {
			Long id = iter.next();
			delete = getSelection().get(id);

			if (delete) {
				us.delete(id);
				iter.remove();
			}
		}
		return getPreviousView();
	}

	
	
}
